package com.ruoyi.manage.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.manage.mapper.FormSettingSmallMapper;
import com.ruoyi.manage.domain.FormSettingSmall;
import com.ruoyi.manage.service.IFormSettingSmallService;
import org.springframework.transaction.annotation.Transactional;

import static com.ruoyi.common.utils.SecurityUtils.getUsername;

/**
 * 单小项Service业务层处理
 *
 * @author zww
 * @date 2025-07-15
 */
@Service
public class FormSettingSmallServiceImpl implements IFormSettingSmallService {
    @Autowired
    private FormSettingSmallMapper formSettingSmallMapper;

    /**
     * 查询单小项
     *
     * @param formSettingSmallId 单小项主键
     * @return 单小项
     */
    @Override
    public FormSettingSmall selectFormSettingSmallByFormSettingSmallId(Long formSettingSmallId) {
        return formSettingSmallMapper.selectFormSettingSmallByFormSettingSmallId(formSettingSmallId);
    }

    /**
     * 查询单小项列表
     *
     * @param formSettingSmall 单小项
     * @return 单小项
     */
    @Override
    public List<FormSettingSmall> selectFormSettingSmallList(FormSettingSmall formSettingSmall) {
        return formSettingSmallMapper.selectFormSettingSmallList(formSettingSmall);
    }

    /**
     * 新增单小项
     *
     * @param formSettingSmallList 单小项
     * @return 结果
     */
    @Transactional
    @Override
    public int insertFormSettingSmall(List<FormSettingSmall> formSettingSmallList) {
        int rows = 0;
        for (FormSettingSmall formSettingSmall : formSettingSmallList) {
            if (formSettingSmall.getFormSettingSmallId() == null) {
                formSettingSmall.setCreateBy(getUsername());
                rows += formSettingSmallMapper.insertFormSettingSmall(formSettingSmall);
            } else {
                formSettingSmall.setUpdateBy(getUsername());
                rows += formSettingSmallMapper.updateFormSettingSmall(formSettingSmall);
            }
        }
        return rows;
    }

    /**
     * 修改单小项
     *
     * @param formSettingSmall 单小项
     * @return 结果
     */
    @Override
    public int updateFormSettingSmall(FormSettingSmall formSettingSmall) {
        return formSettingSmallMapper.updateFormSettingSmall(formSettingSmall);
    }

    /**
     * 批量删除单小项
     *
     * @param formSettingSmallIds 需要删除的单小项主键
     * @return 结果
     */
    @Override
    public int deleteFormSettingSmallByFormSettingSmallIds(Long[] formSettingSmallIds) {
        return formSettingSmallMapper.deleteFormSettingSmallByFormSettingSmallIds(formSettingSmallIds);
    }

    /**
     * 删除单小项信息
     *
     * @param formSettingSmallId 单小项主键
     * @return 结果
     */
    @Override
    public int deleteFormSettingSmallByFormSettingSmallId(Long formSettingSmallId) {
        return formSettingSmallMapper.deleteFormSettingSmallByFormSettingSmallId(formSettingSmallId);
    }

    /**
     * 根据大项id查询小项
     *
     * @param formSettingBigId 大项id
     * @return 小项列表
     */
    @Override
    public List<FormSettingSmall> selectFormSettingSmallByFormSettingBigId(Long formSettingBigId) {
        return formSettingSmallMapper.selectFormSettingSmallByFormSettingBigId(formSettingBigId);
    }
}
